# -*- coding: UTF-8 -*-

import base
import re

class Radikal(base.Core):

    __label__ = "Радикал-Фото"
    __url__ = "www.radikal.ru"

    def uploadFile(self, image):
        params = {"F": open(image, "rb"), "upload":'yes'}
        f = self.opener.open("http://www.radikal.ru/action.aspx", params)
        data = f.read()
        f.close()
        return data
        
    def response(self, data):
        self.image_link = re.search("id=\"input_link_1\" value=\"(.+?)\"", data).group(1)
        r = re.search("id=\"input_link_3\" value=\"\[URL=(.+?)\]\[IMG\](.+?)\[/IMG\]\[/URL\]\"", data)
        self.ad_link = r.group(1)
        self.thumb_link = r.group(2)
        self.image_name = re.search(".*/(.+)", self.image_link).group(1)
